<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here

// as we are now within the tab box, we have to state (call) the needed information saved in the variables of the parent function
GLOBAL $AppUI, $canRead, $canEdit;

if (!$canRead) {			// lock out users that do not have at least readPermission on this module
	$AppUI->redirect( "m=public&a=access_denied" );
}
//prepare an html table with a head section
?>
<?php
// retrieving some dynamic content using an easy database query
$q  = new DBQuery;
$q->addTable('users', 'u');
$q->addQuery('DISTINCT(user_id), user_username, contact_last_name, contact_first_name,
	permission_user, contact_email, company_name, contact_company');
$q->addJoin('contacts', 'con', 'user_contact = contact_id');
$q->addJoin('companies', 'com', 'contact_company = company_id');
$q->addJoin('permissions', 'per', 'user_id = permission_user');
if (isset($_POST['searchterm']) && $_POST['searchterm'] != '') {
	$q->addWhere("user_username REGEXP '" . $_POST['searchterm'] . "' or concat(contact_first_name, ' ', contact_last_name) REGEXP '" . $_POST['searchterm'] . "'");
}
$q->addGroup('user_id');
$q->addOrder($orderby);
$quotes = $q->loadList();

// pass the query to the database, please consider always using the (still poor) database abstraction layer
// retrieve a list (in form of an indexed array) of einstein quotes via an abstract db method
if ($quotes && is_array($quotes)) {
	echo json_encode($quotes);
}
else {
	echo '';
}
?>
